#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define XH(i,a,b) for(int i = a; i < b; ++i)
#define XXH(i,b,a) for(int i = b; i >= a; --i)
#define Module 998244353
int tmpInt;ll tmpll;string tmpStr;char tmpChar;
vector<int>tmpIntVector;

ll n,m;
vector<string>tmap;

int judge(string *past, ll i, ll j, int tag){
  if(past[i][j] != 'G') return 0;
  /* if(tag != 3 && i - 1 >= 0 && tmap[i - 1][j] == '0' && past[i - 1][j    ] == 'C') { */
  /*   past[i][j] = '.'; */
  /*   tmap[i - 1][j] = '1'; */
  /*   return 1; */
  /* } */ 
  if(tag != 4 && j - 1 >= 0 && tmap[i][j - 1] == '0' && past[i    ][j - 1] == 'C'){
    past[i][j] = '.';
    tmap[i][j - 1] = '1';
    return 1;
  }
  if(tag != 2 && j + 1 <  m && tmap[i][j + 1] == '0' && past[i    ][j + 1] == 'C'){
    past[i][j] = '.';
    tmap[i][j + 1] = '1';
    return 1;
  }
  if(tag != 1 && i + 1 <  n && tmap[i + 1][j] == '0' && past[i + 1][j    ] == 'C'){
    past[i][j] = '.';
    tmap[i + 1][j] = '1';
    return 1;
  }
  return 0;
}

void restoreMap(ll a, ll b){
  for(ll i = a - 2; i < a + 2; ++i)
    for(ll j = b -2; j < b + 2; ++j)
      if(i>=0 && i < n && j >=0 && j< m){
        tmap[i][j] = '0';
      }
}

int count(string *past, ll i, ll j){
  int ret = 0;
  /* if(i - 1 >= 0 && judge(past, i - 1, j    , 1) ) ++ret; */
  if(j - 1 >= 0 && judge(past, i    , j - 1, 2) ) ++ret;
  if(j + 1 <  m && judge(past, i    , j + 1, 4) ) ++ret;
  if(i + 1 <  n && judge(past, i + 1, j    , 3) ) ++ret;
  restoreMap(i, j);
  return ret;
}

void solve(string *past){
  ll ans = 0;
  for(ll i = 0; i < n ; ++i){
    for(ll j = 0; j < m; ++j){
      if(past[i][j] == 'C'){
        ans += count(past, i, j);
      }
      past[i][j] = '.';
    }
  }
  printf("%lld\n", ans);
}

int main(){
  #ifndef ONLINE_JUDGE
    auto start_clock = clock();
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
  #endif

  scanf("%lld%lld", &n, &m);
  tmap.resize(n);
  string pasture[n];
  for(ll i = 0; i < n; ++i){
    cin>>pasture[i];
    for(ll j = 0; j < m; ++j)tmap[i][j] = '0';
  }
  solve(pasture);
  
  
  #ifndef ONLINE_JUDGE
    auto end_clock = clock();
    //cout<<"runtime: "<<(double)(end_clock - start_clock)/CLOCKS_PER_SEC<<"s"<<endl;
  #endif
  return 0;
}
